$.ajax({
    type:"POST",
    url:constUrl+"CategoryServlet",
    dataType:"json",
    data: {
        operateType:"allList",
    },
    success:function(responseText){
        $("#cpunum_div").hide();
        $("input[name=MPI]").click(function(){

            switch($("input[name=MPI]:checked").attr("id")){
                case "is_use_mpi":
                    $("#cpunum_div").show();
                    break;
                case "no_mpi":
                    document.getElementById("cpunum").value = "";
                    $("#cpunum_div").hide();

                    break;
                default:
                    break;
            }
        });
        var typeHtml ='';
        var functionHtml = '';
        for(var i=0;i<responseText.datas.length;i++){
            if(responseText.datas[i].isFunction==1){
                typeHtml+='<option value="'+(responseText.datas[i].categoryId)+'" >'+responseText.datas[i].categoryName+'</option>'
            }else if(responseText.datas[i].isFunction==0){
                functionHtml+='<option value="'+(responseText.datas[i].categoryId)+'" >'+responseText.datas[i].categoryName+'</option>'
            }
        }
        $("#algorithm_type").append(typeHtml);
        $("#algorithm_function").append(functionHtml);
        var ag_xml_string =  parent.$("#jsonInfo").attr("aString");
        var ag_xml_name = parent.$("#jsonInfo").attr("aName");
        var ag_xml_version = parent.$("#jsonInfo").attr("aversion");
        var ag_xml_type = parent.$("#jsonInfo").attr("atype");
        var ag_xml_function = parent.$("#jsonInfo").attr("afunction");
        var ag_xml_companyName = parent.$("#jsonInfo").attr("acompanyName");
        var ag_xml_introduction = parent.$("#jsonInfo").attr("aintroduction");
        var ag_xml_postfix = parent.$("#jsonInfo").attr("apostfix");
        var ag_xml_platform = parent.$("#jsonInfo").attr("aplatform");
        var ag_xml_containGpu = parent.$("#jsonInfo").attr("acontainGpu");
        var ag_xml_useMpi = parent.$("#jsonInfo").attr("auseMpi");
        var ag_xml_cpuNum = parent.$("#jsonInfo").attr("acpuNum");
        var ag_xml_isLeft = parent.$("#jsonInfo").attr("aisLeft");

        var ag_xml_inputCount = parent.$("#jsonInfo").attr("ainputCount");
        var ag_xml_outputCount = parent.$("#jsonInfo").attr("aoutputCount");
        var ag_xml_paramsCount = parent.$("#jsonInfo").attr("aparamsCount");
        var  ag_xml_inputName = new Array();
        var  ag_xml_inputType = new Array();
        var  ag_xml_inputIntroduction = new Array();
        var ag_xml_inputSuffix = new Array();
        for(var i=0;i<ag_xml_inputCount;i++){
            ag_xml_inputName[i] = parent.$("#jsonInfo").attr("inputName"+i);
            ag_xml_inputType[i] = parent.$("#jsonInfo").attr("inputType"+i);
            ag_xml_inputIntroduction[i]=parent.$("#jsonInfo").attr("inputIntroduction"+i);
            ag_xml_inputSuffix[i] = parent.$("#jsonInfo").attr("inputSuffix"+i);
        }
        var  ag_xml_outputName = new Array();
        var  ag_xml_outputType = new Array();
        var  ag_xml_outputIntroduction = new Array();
        var ag_xml_outputSuffix = new Array();
        for(var i=0;i<ag_xml_outputCount;i++){
            ag_xml_outputName[i] = parent.$("#jsonInfo").attr("outputName"+i);
            ag_xml_outputType[i] = parent.$("#jsonInfo").attr("outputType"+i);
            ag_xml_outputIntroduction[i]=parent.$("#jsonInfo").attr("outputIntroduction"+i);
            ag_xml_outputSuffix[i] = parent.$("#jsonInfo").attr("outputSuffix"+i);
        }
        var  ag_xml_paramSymbol = new Array();
        var  ag_xml_paramType = new Array();
        var  ag_xml_paramIntroduction = new Array();
        var ag_xml_paramDefaultValue = new Array();
        for(var i=0;i<ag_xml_paramsCount;i++){
            ag_xml_paramSymbol[i] = parent.$("#jsonInfo").attr("paramSymbol"+i);
            ag_xml_paramType[i]=parent.$("#jsonInfo").attr("paramType"+i);
            ag_xml_paramIntroduction[i]=parent.$("#jsonInfo").attr("paramIntroduction"+i);
            ag_xml_paramDefaultValue[i]=parent.$("#jsonInfo").attr("paramDefaultValue"+i);
        }

        $("#company_name").append(ag_xml_string);
        $("#name").val(ag_xml_name);
        $("#version").val(ag_xml_version);
        // var sss = document.getElementById("algorithm_type").options;
        // console.log(sss);
        var kStr = "-";
        var function_select = document.getElementById("algorithm_function").options;
        console.log(ag_xml_function);
        for(var i = 0;i<function_select.length;i++){

            console.log(function_select[i].text);
            if(function_select[i].text==ag_xml_type){
                $("#algorithm_function").val(function_select[i].value);
                break;
            }else {
                $("#algorithm_function").val(kStr);
            }
        }
        var type_select = document.getElementById("algorithm_type").options;
        console.log(ag_xml_type);
        for(var i = 0;i<type_select.length;i++){

            console.log(type_select[i].text);
            if(type_select[i].text===ag_xml_function){
                $("#algorithm_type").val(type_select[i].value);
                break;
            }else {
                $("#algorithm_type").val(kStr);
            }
        }
        var company_select = document.getElementById("company_name").options;
        for(var i = 0;i<company_select.length;i++){
            if(company_select[i].text==ag_xml_companyName){
                $("#company_name").val(company_select[i].value);
                break;
            }else {
                $("#company_name").val(kStr);
            }
        }
        $("#introduction").val(ag_xml_introduction);
        var postfix = ag_xml_postfix.split(".")[1];
        $("#postfix").val(postfix);
        $("#platform").val(ag_xml_platform);

        var containGpu = ag_xml_containGpu;
        var useMpi = ag_xml_useMpi;
        var isLeft = ag_xml_isLeft;

        if (containGpu=="true"){
            $("#is_use_gpu").attr("checked","checked" );
        }else{
            $("#no_gpu").attr("checked","checked");
        }
        if  (useMpi=="true"){
            $("#is_use_mpi").attr("checked","checked");
            $("#cpunum_div").show();
            $("#cpunum").val(ag_xml_cpuNum);

        }else{
            $("#no_mpi").attr("checked","checked");
        }
        if(isLeft=="true"){
            $("#isGenetic").attr("checked","checked");
        }else{
            $("#noGenetic").attr("checked","checked");
        }



        $("#Num").text(ag_xml_inputCount);
        for (var i = 0; i<ag_xml_inputCount; i++){
            addcounti(i);
        }

        $("#addInputBtn").click(function () {
            addcount();
        });
        $("#deleteInputBtn").click(function () {
            deletecount();
        });
        function addcounti(inputLength) {

            var Area = document.getElementById("InputArea");
            var Num = document.getElementById("Num");

            var temp = inputLength
            temp++;

            var inputpara = "inputpara"+temp;
            var para = "para" + temp;
            var inputName= "input_name" + temp;
            var inputType = "input_type"+temp;
            var inputDetail = "input_introduction"+ temp;
            var inputSuffix = "input_suffix"+temp;
            var inputTypeDiv = "input_type_div"+temp;
            var inputIntroDiv = "input_introduction_div"+temp;
            var inputSuffixDiv = "input_suffix_div"+temp;
            var acplaceholder = "名称"+temp;
            var cinDetailPlaceholder = "描述";
            var suffixAcplaceholder = "后缀"+temp;
            var inputHtml = "";
            if(ag_xml_inputType[inputLength]=="file"){
                inputHtml = '<div class="row '+inputpara+'" id="'+inputpara+'">' +
                    '<div class="col-md-3 areaInput '+para+'">' +
                    '        <input type="text" name="'+inputName+'" id="'+inputName+'" placeholder="'+acplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                    ' </div>' +
                    ' <div class="col-md-3 areaInput '+para+'">' +
                    '        <select id="'+inputType+'" class="col-md-3"style="height: 37px;font-size:small"  >' +
                    '                <option value="file" selected="selected">文件</option>' +
                    '               <option value="directory">目录</option>' +
                    '          </select>' +
                    ' </div>'+
                    '<div class="col-md-3 areaInput '+para+'" id="'+inputIntroDiv+'">' +
                    '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+inputDetail+'" id="'+inputDetail+'" style="display: inline-block;font-size:small; height: 37px"">' +
                    ' </div> ' +
                    ' <div class="col-md-3 areaInput '+para+'" name="'+inputSuffixDiv+'">' +
                    '        <input type="text" name="'+inputSuffix+'" id="'+inputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                    '</div>'+
                    '</div>';
                $("#InputArea").append(inputHtml);

                $("#"+inputName).val(ag_xml_inputName[inputLength]);
                $("#"+inputType).val(ag_xml_inputType[inputLength]);
                $("#"+inputDetail).val(ag_xml_inputIntroduction[inputLength]);
                $("#"+inputSuffix).val(ag_xml_inputSuffix[inputLength]);
                var sel = document.getElementById(inputType);
                sel.onchange = function () {
                    if(sel.options[sel.selectedIndex].value=="directory"){
                        $('#'+inputpara+'>div[name="'+inputSuffixDiv+'"]').remove();
                        $('#'+inputIntroDiv).attr("class","col-md-6 areaInput "+para);

                    }else if(sel.options[sel.selectedIndex].value=="file"){
                        $('#'+inputpara+'>div[name="'+inputSuffixDiv+'"]').remove();
                        $('#'+inputIntroDiv).attr("class","col-md-3 areaInput "+para);
                        var html2 = ' <div class="col-md-3 areaInput '+para+'" name="'+inputSuffixDiv+'">' +
                            '        <input type="text" name="'+inputSuffix+'" id="'+inputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                            '</div>';
                        $('#'+inputpara).append(html2);
                    }
                }

            }else if(ag_xml_inputType[inputLength]=="directory"){
                inputHtml = '<div class="row '+inputpara+'" id="'+inputpara+'">' +
                    '<div class="col-md-3 areaInput '+para+'">' +
                    '        <input type="text" name="'+inputName+'" id="'+inputName+'" placeholder="'+acplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                    ' </div>' +
                    ' <div class="col-md-3 areaInput '+para+'">' +
                    '        <select id="'+inputType+'" class="col-md-3"style="height: 37px;font-size:small"  >' +
                    '                <option value="file" selected="selected">文件</option>' +
                    '               <option value="directory">目录</option>' +
                    '          </select>' +
                    ' </div>'+
                    '<div class="col-md-6 areaInput '+para+'" id="'+inputIntroDiv+'">' +
                    '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+inputDetail+'" id="'+inputDetail+'" style="display: inline-block;font-size:small; height: 37px"">' +
                    ' </div> ' +
                    '</div>';
                $("#InputArea").append(inputHtml);
                $("#"+inputName).val(ag_xml_inputName[inputLength]);
                $("#"+inputType).val(ag_xml_inputType[inputLength]);
                $("#"+inputDetail).val(ag_xml_inputIntroduction[inputLength]);
                var sel = document.getElementById(inputType);
                sel.onchange = function () {
                    if(sel.options[sel.selectedIndex].value=="directory"){
                        $('#'+inputpara+'>div[name="'+inputSuffixDiv+'"]').remove();
                        $('#'+inputIntroDiv).attr("class","col-md-6 areaInput "+para);

                    }else if(sel.options[sel.selectedIndex].value=="file"){
                        $('#'+inputpara+'>div[name="'+inputSuffixDiv+'"]').remove();
                        $('#'+inputIntroDiv).attr("class","col-md-3 areaInput "+para);
                        var html2 = ' <div class="col-md-3 areaInput '+para+'" name="'+inputSuffixDiv+'">' +
                            '        <input type="text" name="'+inputSuffix+'" id="'+inputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                            '</div>';
                        $('#'+inputpara).append(html2);
                    }
                }
            }
            //删除按钮
            var deleteBtn = document.getElementById("deleteInputBtn");
            deleteBtn.removeAttribute("disabled");
            return false;
        }

        function addcount() {
            var Num = document.getElementById("Num");
            var temp = Num.innerHTML;
            temp++;

            Num.innerHTML = temp;
            var inputpara = "inputpara"+temp;
            var para = "para" + temp;
            var inputName= "input_name" + temp;
            var inputType = "input_type"+temp;
            var inputDetail = "input_introduction"+ temp;
            var inputSuffix = "input_suffix"+temp;
            var inputTypeDiv = "input_type_div"+temp;
            var inputIntroDiv = "input_introduction_div"+temp;
            var inputSuffixDiv = "input_suffix_div"+temp;
            var acplaceholder = "名称"+temp;
            var cinDetailPlaceholder = "描述";
            var suffixAcplaceholder = "后缀"+temp;


            var inputHtml = '<div class="row '+inputpara+'" id="'+inputpara+'">' +
                '<div class="col-md-3 areaInput '+para+'">' +
                '        <input type="text" name="'+inputName+'" id="'+inputName+'" placeholder="'+acplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                ' </div>' +
                ' <div class="col-md-3 areaInput '+para+'">' +
                '        <select id="'+inputType+'" class="col-md-3"style="height: 37px;font-size:small"  >' +
                '                <option value="file" selected="selected">文件</option>' +
                '               <option value="directory">目录</option>' +
                '          </select>' +
                ' </div>'+
                '<div class="col-md-3 areaInput '+para+'" id="'+inputIntroDiv+'">' +
                '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+inputDetail+'" id="'+inputDetail+'" style="display: inline-block;font-size:small; height: 37px"">' +
                ' </div> ' +
                ' <div class="col-md-3 areaInput '+para+'" name="'+inputSuffixDiv+'">' +
                '        <input type="text" name="'+inputSuffix+'" id="'+inputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                '</div>'+
                '</div>'
            $("#InputArea").append(inputHtml);

            var sel = document.getElementById(inputType);
            sel.onchange = function () {
                if(sel.options[sel.selectedIndex].value=="directory"){
                    $('#'+inputpara+'>div[name="'+inputSuffixDiv+'"]').remove();
                    $('#'+inputIntroDiv).attr("class","col-md-6 areaInput "+para);

                }else if(sel.options[sel.selectedIndex].value=="file"){
                    $('#'+inputpara+'>div[name="'+inputSuffixDiv+'"]').remove();
                    $('#'+inputIntroDiv).attr("class","col-md-3 areaInput "+para);
                    var html2 = ' <div class="col-md-3 areaInput '+para+'" name="'+inputSuffixDiv+'">' +
                        '        <input type="text" name="'+inputSuffix+'" id="'+inputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                        '</div>';
                    $('#'+inputpara).append(html2);
                }
            }
            //删除按钮
            var deleteBtn = document.getElementById("deleteInputBtn");
            deleteBtn.removeAttribute("disabled");
            return false;
        }

        //删除输入数量
        function deletecount() {
            // event.preventDefault();
            var Area = document.getElementById("InputArea");
            // var addNum = document.getElementById("addNum");
            var Num = document.getElementById("Num");
            var temp = Num.textContent;
            var deleteLabel = document.getElementsByClassName("inputpara"+temp);
            Area.removeChild(deleteLabel[0]);
            temp--;
            Num.textContent = temp;
            if(temp === 0){
                var deleteBtn = document.getElementById("deleteInputBtn");
                deleteBtn.setAttribute("disabled","true");
            }
            return false;
        }


        //输出数量

        $("#outputNum").text(ag_xml_outputCount);
        for (var k = 0; k<ag_xml_outputCount;k++){
            addCouti(k);
        }
        $("#addOutputBtn").click(function () {
            addCout();
        });
        $("#deleteOutputBtn").click(function () {
            deletecout();
        });
        //增加输出数量
        function addCouti(outputLength) {

            // event.preventDefault();
            var Area = document.getElementById("outputArea");
            var Num = document.getElementById("outputNum");
            var temp = outputLength
            temp++;
            var outpara = "outpara"+temp;
            var para = "coutPara" + temp;
            var outputName= "output_name" + temp;
            var outputType = "output_type"+temp;
            var outputDetail = "output_introduction" + temp;
            var outputSuffix = "output_suffix"+temp;
            var outputTypeDiv = "output_type_div"+temp;
            var outputIntroDiv = "output_introduction_div"+temp;
            var outputSuffixDiv = "output_suffix_div"+temp;
            var acplaceholder = "名称"+temp;
            var cinDetailPlaceholder = "描述";
            var suffixAcplaceholder = "后缀"+temp;

            if(ag_xml_outputType[outputLength] =="file" ){
                var outputHtml = '<div class="row '+outpara+'" id="'+outpara+'">' +
                    '<div class="col-md-3 areaInput '+para+'">' +
                    '        <input type="text" name="'+outputName+'" id="'+outputName+'" placeholder="'+acplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                    '</div>' +
                    ' <div class="col-md-3 areaInput '+para+'">' +
                    '        <select id="'+outputType+'" class="col-md-3"  style="height: 37px;font-size:small">' +
                    '                <option value="file" selected="selected">文件</option>' +
                    '                <option value="directory">目录</option>' +
                    '            </select>' +
                    '    </div>'+
                    ' <div class="col-md-3  areaInput '+para+'" id="'+outputIntroDiv+'">' +
                    '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+outputDetail+'" id="'+outputDetail+'" style="display: inline-block;font-size:small; height: 37px">' +
                    ' </div>' +
                    ' <div class="col-md-3  areaInput '+para+'" name="'+outputSuffixDiv+'">' +
                    '        <input type="text" placeholder="'+suffixAcplaceholder+'" name="'+outputSuffix+'" id="'+outputSuffix+'" style="display: inline-block;font-size:small; height: 37px">' +
                    ' </div>' +
                    '</div>'
                $("#outputArea").append(outputHtml);

                $("#"+outputName).val(ag_xml_outputName[outputLength]);
                // $("option[value="+algorithmOutputs[outputLength].type+"]").attr("selected","selected");
                $("#"+outputType).val(ag_xml_outputType[outputLength]);
                $("#"+outputDetail).val(ag_xml_outputIntroduction[outputLength]);
                $("#"+outputSuffix).val(ag_xml_outputSuffix[outputLength]);
                var sel = document.getElementById(outputType);
                sel.onchange = function () {
                    if(sel.options[sel.selectedIndex].value=="directory"){
                        $('#'+outpara+'>div[name="'+outputSuffixDiv+'"]').remove();
                        $('#'+outputIntroDiv).attr("class","col-md-6 areaInput "+para);

                    }else if(sel.options[sel.selectedIndex].value=="file"){
                        $('#'+outpara+'>div[name="'+outputSuffixDiv+'"]').remove();
                        $('#'+outputIntroDiv).attr("class","col-md-3 areaInput "+para);
                        var html2 = ' <div class="col-md-3 areaInput '+para+'" name="'+outputSuffixDiv+'">' +
                            '        <input type="text" name="'+outputSuffix+'" id="'+outputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                            '</div>';
                        $('#'+outpara).append(html2);
                    }
                }

            }else if(ag_xml_outputType[outputLength] =="directory"){
                var outputHtml = '<div class="row '+outpara+'" id="'+outpara+'">' +
                    '<div class="col-md-3 areaInput '+para+'">' +
                    '        <input type="text" name="'+outputName+'" id="'+outputName+'" placeholder="'+acplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                    '</div>' +
                    ' <div class="col-md-3 areaInput '+para+'">' +
                    '        <select id="'+outputType+'" class="col-md-3"  style="height: 37px;font-size:small">' +
                    '                <option value="file" selected="selected">文件</option>' +
                    '                <option value="directory">目录</option>' +
                    '            </select>' +
                    '    </div>'+
                    ' <div class="col-md-6 areaInput '+para+'" id="'+outputIntroDiv+'">' +
                    '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+outputDetail+'" id="'+outputDetail+'" style="display: inline-block;font-size:small; height: 37px">' +
                    ' </div>' +
                    '</div>'
                $("#outputArea").append(outputHtml);

                $("#"+outputName).val(ag_xml_outputName[outputLength]);
                // $("option[value="+algorithmOutputs[outputLength].type+"]").attr("selected","selected");
                $("#"+outputType).val(ag_xml_outputType[outputLength]);
                $("#"+outputDetail).val(ag_xml_outputIntroduction[outputLength]);
                var sel = document.getElementById(outputType);
                sel.onchange = function () {
                    if(sel.options[sel.selectedIndex].value=="directory"){
                        $('#'+outpara+'>div[name="'+outputSuffixDiv+'"]').remove();
                        $('#'+outputIntroDiv).attr("class","col-md-6 areaInput "+para);

                    }else if(sel.options[sel.selectedIndex].value=="file"){
                        $('#'+outpara+'>div[name="'+outputSuffixDiv+'"]').remove();
                        $('#'+outputIntroDiv).attr("class","col-md-3 areaInput "+para);
                        var html2 = ' <div class="col-md-3 areaInput '+para+'" name="'+outputSuffixDiv+'">' +
                            '        <input type="text" name="'+outputSuffix+'" id="'+outputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                            '</div>';
                        $('#'+outpara).append(html2);
                    }
                }
            }



            //删除按钮
            var deleteBtn = document.getElementById("deleteOutputBtn");
            deleteBtn.removeAttribute("disabled");
            return false;
        }

        function addCout() {
            // event.preventDefault();
            var Area = document.getElementById("outputArea");
            var Num = document.getElementById("outputNum");
            var temp = Num.innerHTML;
            temp++;
            Num.innerHTML = temp;
            var outpara = "outpara"+temp;
            var para = "coutPara" + temp;
            var outputName= "output_name" + temp;
            var outputType = "output_type"+temp;
            var outputDetail = "output_introduction" + temp;
            var outputSuffix = "output_suffix"+temp;
            var outputTypeDiv = "output_type_div"+temp;
            var outputIntroDiv = "output_introduction_div"+temp;
            var outputSuffixDiv = "output_suffix_div"+temp;
            var acplaceholder = "名称"+temp;
            var cinDetailPlaceholder = "描述";
            var suffixAcplaceholder = "后缀"+temp;



            var outputHtml = '<div class="row '+outpara+'" id="'+outpara+'">' +
                '<div class="col-md-3 areaInput '+para+'">' +
                '        <input type="text" name="'+outputName+'" id="'+outputName+'" placeholder="'+acplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                '</div>' +
                ' <div class="col-md-3 areaInput '+para+'">' +
                '        <select id="'+outputType+'" class="col-md-3"  style="height: 37px;font-size:small">' +
                '                <option value="file" selected="selected">文件</option>' +
                '                <option value="directory">目录</option>' +
                '            </select>' +
                '    </div>'+
                ' <div class="col-md-3  areaInput '+para+'" id="'+outputIntroDiv+'">' +
                '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+outputDetail+'" id="'+outputDetail+'" style="display: inline-block;font-size:small; height: 37px">' +
                ' </div>' +
                ' <div class="col-md-3  areaInput '+para+'" name="'+outputSuffixDiv+'">' +
                '        <input type="text" placeholder="'+suffixAcplaceholder+'" name="'+outputSuffix+'" id="'+outputSuffix+'" style="display: inline-block;font-size:small; height: 37px">' +
                ' </div>' +
                '</div>'
            $("#outputArea").append(outputHtml);
            var sel = document.getElementById(outputType);
            sel.onchange = function () {
                if(sel.options[sel.selectedIndex].value=="directory"){
                    $('#'+outpara+'>div[name="'+outputSuffixDiv+'"]').remove();
                    $('#'+outputIntroDiv).attr("class","col-md-6 areaInput "+para);

                }else if(sel.options[sel.selectedIndex].value=="file"){
                    $('#'+outpara+'>div[name="'+outputSuffixDiv+'"]').remove();
                    $('#'+outputIntroDiv).attr("class","col-md-3 areaInput "+para);
                    var html2 = ' <div class="col-md-3 areaInput '+para+'" name="'+outputSuffixDiv+'">' +
                        '        <input type="text" name="'+outputSuffix+'" id="'+outputSuffix+'" placeholder="'+suffixAcplaceholder+'" style="display: inline-block;font-size:small; height: 37px">' +
                        '</div>';
                    $('#'+outpara).append(html2);
                }
            }
            //删除按钮
            var deleteBtn = document.getElementById("deleteOutputBtn");
            deleteBtn.removeAttribute("disabled");
            return false;
        }

        //删除输出数量
        function deletecout() {

            // event.preventDefault();
            var Area = document.getElementById("outputArea");
            var Num = document.getElementById("outputNum");
            var temp = Num.textContent;
            var deleteLabel = document.getElementsByClassName("outpara"+temp);
            Area.removeChild(deleteLabel[0]);
            temp--;
            Num.textContent = temp
            if(temp === 0){
                var deleteBtn = document.getElementById("deleteOutputBtn");
                deleteBtn.setAttribute("disabled","true")
            }
            return false;
        }

        //输入参数
        $("#paramNum").text(ag_xml_paramsCount);
        for (var j = 0; j<ag_xml_paramsCount; j++){
            addCinParai(j);
        }
        $("#addParamBtn").click(function () {
            addCinPara();
        });
        $("#deleteParamBtn").click(function () {
            deleteCinPara();
        });
        //增加输入参数
        function addCinParai(paraLength) {

            // event.preventDefault();
            var temp = paraLength;
            temp++;
            var parames = "parames"+temp;
            var para = "cinPara" + temp;
            var paramType =  "param_id" + temp;
            var paramSymbol=  "param_symbol" + temp;
            var paramDetail=  "param_introduction" + temp;
            var paramDefaultValue = "paramDefaultValue"+temp;

            var symbolPlace = "符号"+ temp;
            var cinDetailPlaceholder = "描述"+temp;
            var defalutPlaceholder = "默认值"+temp;

            var paramHtml = '<div class="row '+parames+'"><div class="col-md-3 areaInput '+para+'">' +
                '        <input type="text" name="'+paramSymbol+'" id="'+paramSymbol+'" placeholder="'+symbolPlace+'" style="display: inline-block;font-size:small; height: 37px">' +
                '    </div>' +
                ' <div class="col-md-3 areaInput '+para+'">' +
                '        <select id="'+paramType+'" class="col-md-3"  style="' +
                '    height: 37px;font-size:small' +
                '"  >' +
                '                <option value="int">int</option>' +
                '                <option value="double">double</option>' +
                '                <option value="float">float</option>' +
                '                <option value="string">string</option>' +
                '            </select>' +
                '    </div>'+
                '    <div class="col-md-3 areaInput '+para+'">' +
                '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+paramDetail+'" id="'+paramDetail+'" style="display: inline-block;font-size:small; height: 37px">' +
                '    </div>' +
                '    <div class="col-md-3 areaInput '+para+'">' +
                '        <input type="text" placeholder="'+defalutPlaceholder+'" name="'+paramDefaultValue+'" id="'+paramDefaultValue+'" style="display: inline-block;font-size:small; height: 37px">' +
                '    </div>'+
                '</div>'
            $("#paramArea").append(paramHtml);
            $("#"+paramSymbol).val(ag_xml_paramSymbol[paraLength]);
            $("#"+paramType).val(ag_xml_paramType[paraLength]);
            // $("option[value="+algorithmParams[paraLength].paramType+"]").attr("selected","selected");
            $("#"+paramDetail).val(ag_xml_paramIntroduction[paraLength]);
            $("#"+paramDefaultValue).val(ag_xml_paramDefaultValue[paraLength]);

            //删除按钮
            var deleteBtn = document.getElementById("deleteParamBtn");
            deleteBtn.removeAttribute("disabled");
            // console.log(deleteBtn);
            return false;
        }

        function addCinPara() {

            var Area = document.getElementById("paramArea");
            var Num = document.getElementById("paramNum");
            var temp = Num.innerHTML;
            temp++;
            Num.innerHTML = temp;
            var parames = "parames"+temp;
            var para = "cinPara" + temp;
            var paramType =  "param_id" + temp;
            var paramSymbol=  "param_symbol" + temp;
            var paramDetail=  "param_introduction" + temp;
            var paramDefaultValue = "paramDefaultValue"+temp;

            var symbolPlace = "符号"+ temp;
            var cinDetailPlaceholder = "描述"+temp;
            var defalutPlaceholder = "默认值"+temp;

            var paramHtml = '<div class="row '+parames+'"><div class="col-md-3 areaInput '+para+'">' +
                '        <input type="text" name="'+paramSymbol+'" id="'+paramSymbol+'" placeholder="'+symbolPlace+'" style="display: inline-block;font-size:small; height: 37px">' +
                '    </div>' +
                ' <div class="col-md-3 areaInput '+para+'">' +
                '        <select id="'+paramType+'" class="col-md-3"  style="' +
                '    height: 37px;font-size:small' +
                '"  >' +
                '                <option value="int">int</option>' +
                '                <option value="double">double</option>' +
                '                <option value="float">float</option>' +
                '                <option value="string">string</option>' +
                '            </select>' +
                '    </div>'+
                '    <div class="col-md-3 areaInput '+para+'">' +
                '        <input type="text" placeholder="'+cinDetailPlaceholder+'" name="'+paramDetail+'" id="'+paramDetail+'" style="display: inline-block;font-size:small; height: 37px">' +
                '   </div> ' +
                '    <div class="col-md-3 areaInput '+para+'">' +
                '        <input type="text" placeholder="'+defalutPlaceholder+'" name="'+paramDefaultValue+'" id="'+paramDefaultValue+'" style="display: inline-block;font-size:small; height: 37px">' +
                '   </div> '+
                '</div>'
            $("#paramArea").append(paramHtml);

            //删除按钮
            var deleteBtn = document.getElementById("deleteParamBtn");
            deleteBtn.removeAttribute("disabled");
            // console.log(deleteBtn);
            return false;
        }

        //删除输入参数
        function deleteCinPara() {
            // event.preventDefault();
            var Area = document.getElementById("paramArea");
            var Num = document.getElementById("paramNum");
            var temp = Num.textContent;
            var deleteLabel = document.getElementsByClassName("parames"+temp);
            Area.removeChild(deleteLabel[0]);
            temp--;
            Num.textContent = temp;
            if(temp === 0){
                var deleteBtn = document.getElementById("deleteParamBtn");
                deleteBtn.setAttribute("disabled","true")
            }
        }


    }
});


function xmlRegister() {
    var xmlinfo=new Object();
    xmlinfo.name=document.getElementById("name").value;
    input_count_num=document.getElementById("Num").textContent;
    var inputinfo=new Array();
    for(var i=0;i< input_count_num;i++)
    {
        var temp=i+1;
        var inputName= "input_name" +temp;
        var type = "input_type"+temp;
        var inputDetail = "input_introduction"+temp;
        var inputSufficcx = "input_suffix"+temp;
        if(document.getElementById(type).value=="file"){
            inputinfo.push({
                inputName:document.getElementById(inputName).value,
                type:document.getElementById(type).value,
                inputIntroduction:document.getElementById(inputDetail).value,
                suffix:document.getElementById(inputSufficcx).value
            })
        }else if(document.getElementById(type).value=="directory"){
            inputinfo.push({
                inputName:document.getElementById(inputName).value,
                type:document.getElementById(type).value,
                inputIntroduction:document.getElementById(inputDetail).value,
                suffix:""
            })
        }
    }
    // console.log(inputinfo);
    xmlinfo.inputCount=inputinfo;
    output_count_num=document.getElementById("outputNum").textContent;
    // console.log( output_count_num);
    var outputinfo=new Array();
    for(var i=0;i< output_count_num;i++)
    {
        var temp=i+1;
        var outputName= "output_name" +temp;
        var type = "output_type"+temp;
        var outputDetail = "output_introduction" +temp;
        var outputSuffix = "output_suffix"+temp;
        if(document.getElementById(type).value=="file"){
            outputinfo.push({
                outputName:document.getElementById(outputName).value,
                type:document.getElementById(type).value,
                outputIntroduction:document.getElementById(outputDetail).value,
                suffix:document.getElementById(outputSuffix).value
            })
        }else if(document.getElementById(type).value=="directory"){
            outputinfo.push({
                outputName:document.getElementById(outputName).value,
                type:document.getElementById(type).value,
                outputIntroduction:document.getElementById(outputDetail).value,
                suffix:""
            })
        }
    }

    xmlinfo.outputCount=outputinfo;
    params_count_num=document.getElementById("paramNum").textContent;
    // console.log(params_count_num);
    var paramInfo=new Array();
    for(var i=0;i<params_count_num;i++)
    {
        var temp=i+1;
        var paramName =  "param_id" +temp;
        var paramSymbol=  "param_symbol" +temp;
        var paramDetail=  "param_introduction" + temp;
        var paramDefaultValue = "paramDefaultValue"+temp;
        paramInfo.push({
            paramSymbol:document.getElementById(paramSymbol).value,
            paramType:document.getElementById(paramName).value,
            paramIntroduction:document.getElementById(paramDetail).value,
            paramDefaultValue:document.getElementById(paramDefaultValue).value
        })
    }
    // console.log(paramInfo);
    xmlinfo.paramsCount=paramInfo;
    xmlinfo.version=document.getElementById("version").value;
    xmlinfo.introduction=document.getElementById("introduction").value;
    xmlinfo.algorithmType=document.getElementById("algorithm_type").value;
    xmlinfo.postfix="."+document.getElementById("postfix").value;
    xmlinfo.companyName=document.getElementById("company_name").value;
    xmlinfo.platform=document.getElementById("platform").value;
    var cpunum = document.getElementById("cpunum").value;
    if(cpunum==""){
        xmlinfo.cpuNum = 0;
    }else{
        xmlinfo.cpuNum = cpunum;
    }
    xmlinfo.algorithmFunction=document.getElementById("algorithm_function").value;
    var GPU=document.getElementsByName("GPU");
    for(var i=0;i<GPU.length;i++)
    {
        if(GPU[i].checked)
        {
            xmlinfo.isContainGpu=GPU[i].value;
            break;
        }
        else
        {
            continue;
        }
    }
    var MPI=document.getElementsByName("MPI")
    for(var i=0;i<MPI.length;i++)
    {
        if(MPI[i].checked)
        {
            xmlinfo.isUseMpi=MPI[i].value;
            break;
        }
        else
        {
            continue;
        }
    }
    var Left=document.getElementsByName("genetic")
    for(var i=0;i<MPI.length;i++)
    {
        if(Left[i].checked)
        {
            xmlinfo.genetic=Left[i].value;
            break;
        }
        else
        {
            continue;
        }
    }

    console.log(xmlinfo);
    var updateinfo_json = JSON.stringify(xmlinfo);

    // var fileinfo=document.getElementById("file");
    var fileinfo = parent.document.getElementById("paramxmlfile");
    console.log(fileinfo);
    var file=new FormData();
    file.append('algorithm',updateinfo_json);
    file.append('file',fileinfo.files[0]);
    console.log(file);

    var validators = new  InputValidators();

    validators.importStrategies(validationStrategies);

    validators.addValidationStrategy('isEqual',  function(element, errMsg, value1, value2) {
        if(value1 !== value2) {
            return this.buildInvalidObj(element, errMsg, value1 );
        }
    });
    //算法名称
    var ag_name = document.getElementById('name');
    validators.addValidator('isNoEmpty', ag_name, '算法名称未填写，请返回填写', ag_name.value);
    // validators.addValidator('minLength:3', ag_name, '算法名称的字符个数必须是3到20个', ag_name.value);
    // validators.addValidator('maxLength:20', ag_name, '算法名称的字符个数必须是3到20个', ag_name.value);
    //算法版本号
    var ag_version = document.getElementById('version');
    validators.addValidator('isNoEmpty', ag_version, '算法版本未填写，请返回填写', ag_version.value);
    //算法功能选择
    var ag_function = document.getElementById('algorithm_function');
    validators.addValidator('isNoEmpty', ag_function, '算法功能未选择，请返回选择', ag_function.value);
    //算法类型选择
    var ag_type = document.getElementById('algorithm_type');
    validators.addValidator('isNoEmpty', ag_type, '算法类型未选择，请返回选择', ag_type.value);
  /*  //文件
    var paramFlieresString=$("#file");
    var str = paramFlieresString.val().split("\\");
    var paramFlieres = str[str.length-1];
    validators.addValidator('isNoEmpty', paramFlieresString, '没有选择文件，请返回选择文件', paramFlieres);*/
    //算法研制单位
    var ag_company = document.getElementById('company_name');
    validators.addValidator('isNoEmpty', ag_company, '算法研制单位未选择，请返回选择', ag_company.value);
    //算法简介
    var ag_introduction =document.getElementById("introduction");
    validators.addValidator('isNoEmpty', ag_introduction, '算法简介未填写，请返回填写', ag_introduction.value);
    // validators.addValidator('minLength:3', ag_introduction, '算法简介包含的字符少于3个字符，请返回选择', ag_introduction.value);
    // validators.addValidator('maxLength:250', ag_introduction, '算法类型未选择，请返回选择', ag_introduction.value);
    //算法后缀
    var ag_postfix = document.getElementById('postfix');
    validators.addValidator('isNoEmpty', ag_postfix, '算法后缀未选择，请返回选择', ag_postfix.value);
    //算法使用平台
    var ag_platform = document.getElementById('platform');
    validators.addValidator('isNoEmpty', ag_platform, '算法使用平台未选择，请返回选择', ag_platform.value);
    //是否使用gpu
    var ag_gpu=document.getElementsByName("GPU");
    validators.addValidator('isCheck', ag_gpu, '请选择是否使用GPU', ag_gpu);
    //是否使用MPI
    var ag_mpi=document.getElementsByName("MPI");
    validators.addValidator('isCheck', ag_mpi, '请选择是否使用MPI', ag_mpi);
    if($("input[name=MPI]:checked").attr("id")=="is_use_mpi"){
        var ag_cpunum = document.getElementById("cpunum")
        validators.addValidator('isInteger', ag_cpunum, '请正确填写CPU个数', ag_cpunum.value);
    }
    //是否是遗留算法
    var ag_genetic=document.getElementsByName("genetic");
    validators.addValidator('isCheck', ag_genetic, '请选择是否是遗留算法', ag_genetic);
    // for(var i = 0;i<input_count_num;i++){
    //     var temp = i+1;
    //     var type = "input_type"+temp;
    //     if(document.getElementById(type).value=="file"){
    //         var inputSuffix = "input_suffix"+temp;
    //         var ag_inputSuffix = document.getElementById(inputSuffix);
    //         validators.addValidator('isNotEmpty', ag_inputSuffix, '请正确填写第'+temp+'个输入参数的后缀,后缀以“.”开头且长度不小于1', ag_inputSuffix.value);
    //     }
    // }
    //
    // for(var i = 0;i<output_count_num;i++){
    //     var temp = i+1;
    //     var type = "output_type"+temp;
    //     if(document.getElementById(type).value=="file"){
    //         var outputSuffix = "output_suffix"+temp;
    //         var ag_outputSuffix = document.getElementById(outputSuffix);
    //         validators.addValidator('isNotEmpty', ag_outputSuffix, '请正确填写第'+temp+'个输出参数的后缀,后缀以“.”开头且长度不小于1', ag_outputSuffix.value);
    //     }
    // }
    var result = validators.check();
    if(result){
        layer.msg(result.errMsg);
        // alert(result.errMsg);
        result.element.focus();
        result.element.select();
        return false;
    }
    $.ajax({
        type:"POST",
        url:constUrl+"RegisterAlgorithm",
        processData: false,
        contentType: false,
        // dataType:"json",
        data: file,
        success:function(responseText){
            var res = JSON.stringify(responseText);
            responseText=eval("("+responseText+")");
            // console.log(responseText.result);
            if(responseText.result==true)
            {
                var index = parent.layer.getFrameIndex(window.name);
                layer.confirm('添加成功！',{
                    btn:['确定']
                },function () {
                    parent.location.reload(index);
                    self.location=constUrl + 'views/algorithm/list.action';
                })
            }
            else{

                layer.msg(responseText.message+",请检查是否填写完全！");
            }

        },
        error:function(responseText) {

            layer.msg('添加失败！!');
        },
    })
}

//验证准备
//输入验证器
function InputValidators(){
    this.validators = [];
    this.strategies = {};
}

//添加验证方法
//参数:
//  rule: 验证策略字符串
//  element: 被验证的dom元素
//  errMsg: 验证失败时显示的提示信息
//  value: 被验证的值
InputValidators.prototype.addValidator = function(rule, element, errMsg, value) {
    var that = this;
    var ruleElements = rule.split(":");

    this.validators.push(function() {
        var strategy = ruleElements.shift();
        var params = ruleElements;
        params.unshift(value);
        params.unshift(errMsg);
        params.unshift(element);

        return that.strategies[strategy].apply(that, params);
    });
};

//添加验证策略函数
//参数:
//  name: 策略名称
//  strategy: 策略函数
InputValidators.prototype.addValidationStrategy = function(name, strategy){
    this.strategies[name] = strategy;
};

//从策略对象导入验证策略函数
//参数:
//  strategies: 包含各种策略函数的对象
InputValidators.prototype.importStrategies = function(strategies) {
    for(var strategyName in strategies) {
        this.addValidationStrategy(strategyName, strategies[strategyName]);
    }
};

//验证失败时，将相关的错误信息打包返回
//参数:
//  element: dom元素
//   errMsg: 验证失败时的提示消息
//    value: 被验证的值
InputValidators.prototype.buildInvalidObj = function(element, errMsg, value){
    return {
        'value': value,
        'element': element,
        'errMsg': errMsg
    };
};

//开始验证
InputValidators.prototype.check = function() {
    for(var i = 0, validator; validator = this.validators[i++];){
        var result = validator();
        if(result) {
            return result;
        }
    }
};

//验证策略对象，包含默认的验证策略函数
var validationStrategies = {
    isNoEmpty: function(element, errMsg, value) {
        if(value === '') {
            return this.buildInvalidObj(element, errMsg, value );
        }
    },
    isNoUndefined: function(element, errMsg, value) {
        if(value === "undefined") {
            return this.buildInvalidObj(element, errMsg, value );
        }
    },
    isInteger:function (element, errMsg, value) {
        var reg = /^[0-9]*[1-9][0-9]*$/ ;
        if(!reg.test(value)){
            return this.buildInvalidObj(element, errMsg, value);
        }
    },
    isRight:function (element, errMsg, value) {
        if(value>100){
            return this.buildInvalidObj(element, errMsg, value);
        }
    },
    isCheck:function (element, errMsg, value) {
        var isValue="";
        for(var i=0;i<value.length;i++)
        {
            if(value[i].checked)
            {
                isValue=value[i].value;
                break;
            }
            else
            {
                continue;
            }
        }

        if(isValue==""){
            return this.buildInvalidObj(element, errMsg, value);
        }
    },
    isNotEmpty:function (element, errMsg, value) {
        var fdstrat = value.indexOf(".");
        if(fdstrat==-1||value.length<=1){
            return this.buildInvalidObj(element, errMsg, value);
        }
    },
    minLength: function(element, errMsg, value, length) {
        if(value.length < length){
            return this.buildInvalidObj(element, errMsg, value);
        }
    },

    maxLength: function(element, errMsg, value, length) {
        if(value.length > length){
            return this.buildInvalidObj(element, errMsg, value);
        }
    },

    isMail: function(element, errMsg, value, length) {
        var reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
        if(!reg.test(value)){
            return this.buildInvalidObj(element, errMsg, value);
        }
    }
};


function fileShowMess() {
    var paramFlieresString=$("#file").val();
    var str = paramFlieresString.split("\\");
    var paramFlieres = str[str.length-1];
    if(paramFlieres!=""){
        $('#fileShow_div').html(paramFlieres);
        $("#fileShow_div").show();

    }else{
        $('#fileShow_div').html('您还没有输入任何东西');
        $("#fileShow_div").show();
    }
}
$('.actions-btn').on("click","#closeLayer",function () {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
})

